# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x, left=None, right=None):
        self.val = x
        self.left = left
        self.right = right

class Solution:
    def __init__(self, paths=[]):
        self.paths = paths

    def _binaryTreePaths(self, root: TreeNode, now_path: str):
        new_path = now_path + '->' + str(root.val)
        if not root.left and not root.right:
            self.paths.append(new_path)
            return self.paths
        if root.left:
            self._binaryTreePaths(root.left, new_path)
        if root.right:
            self._binaryTreePaths(root.right, new_path)

    def binaryTreePaths(self, root: TreeNode) -> 'List[str]':
        if root is None:
            return []
        if not root.left and not root.right:
            self.paths.append(str(root.val))
            return self.paths
        if root.left:
            self._binaryTreePaths(root.left, str(root.val))
        if root.right:
            self._binaryTreePaths(root.right, str(root.val))
        return self.paths

if __name__ == "__main__":
    s = Solution()
    root = TreeNode(1, left=TreeNode(2, right=TreeNode(5)), right=TreeNode(3))
    print(s.binaryTreePaths(root))